package xml;

import javax.xml.bind.annotation.adapters.*;
import cuShapes.*;
import java.util.*;

public class LinesAdapter extends XmlAdapter<LineListType, List<PQLine>> {
	// adapt original Java construct to a type, NotificationsType,
	// which we can easily map to the XML output we want
	public LineListType marshal(List<PQLine> lines) throws Exception {
		List<StraightLine> straightLines = new ArrayList<StraightLine>();
		List<ArcLine> arcLines = new ArrayList<ArcLine>();

		for (PQLine e : lines) {
			if (e instanceof StraightLine) {
				straightLines.add((StraightLine) e);
			} else if (e instanceof ArcLine){
				arcLines.add((ArcLine) e);
			}
		}
		return new LineListType(straightLines, arcLines);
	}

	// reverse operation: map XML type to Java
	public List<PQLine> unmarshal(LineListType lineList) throws Exception { 
		List<PQLine> lines = new ArrayList<PQLine>();
        lines.addAll(lineList.getStraightLines());
        lines.addAll(lineList.getArcLines());
        
        return lines;
	}
}
